Can also think of this as a pattern of the full knot repeated in a grid. So instead of bouncing off an edge, continue over on block. One will repeat on a loop after LCM/p heights or LCM/q widths, and by then the loop/straight line would have covered p/GCD points on left edge and q/GCD points on top edge of original grid. Since all p left-points have to be covered eventually, the number of loops is GCD.